package com.sgb.kjwl.view.ui.activity.home;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;

import android.text.InputFilter;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;


import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivitySearch5Binding;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.utils.ChineseEnglishAndNumberFilter;
import com.sgb.link.event.LeaseEvent;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.MToast;

import org.greenrobot.eventbus.EventBus;
/**
 * @author: 王彬臣
 * @date:
 * @Description: 物流搜索
 */
public class TransportSearchActivity extends AppActivity {
     ActivitySearch5Binding binding;

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, TransportSearchActivity.class);
        context.startActivity(intent);
    }
    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        super.setupActivityComponent(appComponent);
    }

    @Override
    protected void initView() {
        binding=DataBindingUtil.setContentView(this,R.layout.activity_search5);
        binding.ivBack.setOnClickListener(this);
        binding.tvSearch.setOnClickListener(this);
        binding.etView.setHint("输入关键字搜索（车型、装卸地等）");
        binding.etView.setFilters(new InputFilter[]{new ChineseEnglishAndNumberFilter()});
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;


            case R.id.tv_search:
               String searchText=binding.etView.getText().toString();
                hideKeyboard();
                if (!TextUtils.isEmpty(searchText)) {
                    EventBus.getDefault().post(LeaseEvent.make().setMessageTag(EventConstant.SEARCH_GOOODS_CARS).setMessageData(searchText));
                }else{
                    MToast.showToast(this,"请输入关键字");
                }
                break;

        }
    }
    /**
     * 获取InputMethodManager，隐藏软键盘
     */
    private void hideKeyboard() {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        // 隐藏软键盘
        imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getWindowToken(), 0);
    }
}
